Add bond migration#57
Merged
jcronenberg merged 2 commits intojcronenberg:wicked-nm-migrationfrom Jan 10, 2024
cfconrad:wicked-nm-migration-add-bonding-again
Merged
Add bond migration#57jcronenberg merged 2 commits intojcronenberg:wicked-nm-migrationfrom cfconrad:wicked-nm-migration-add-bonding-again
jcronenberg merged 2 commits intojcronenberg:wicked-nm-migrationfrom
cfconrad:wicked-nm-migration-add-bonding-again
Conversation
jcronenberg
requested changes
Jan 4, 2024
rust/migrate-wicked/src/interface.rs
Outdated
Comment on lines
135
to
484
Owner
There was a problem hiding this comment.
Suggested change
| if let Some(dummy) = &self.dummy { | |
| if let Some(address) = &dummy.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| } else if let Some(ethernet) = &self.ethernet { | |
| if let Some(ethernet) = &self.ethernet { | |
| if let Some(address) = ðernet.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| } | |
| if self.dummy.is_some() { | |
| if let Some(dummy) = &self.dummy { | |
| if let Some(address) = &dummy.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| connection.config = model::ConnectionConfig::Dummy | |
| } else if let Some(bond) = &self.bond { | |
| if let Some(address) = &bond.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| connection.config = bond.into() | |
| } else { | |
| connection.config = model::ConnectionConfig::Ethernet | |
| }; | |
| if let Some(ethernet) = &self.ethernet { | |
| if let Some(address) = ðernet.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| connection.config = model::ConnectionConfig::Ethernet | |
| } else if let Some(dummy) = &self.dummy { | |
| if let Some(address) = &dummy.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| connection.config = model::ConnectionConfig::Dummy | |
| } else if let Some(bond) = &self.bond { | |
| if let Some(address) = &bond.address { | |
| connection.mac_address = MacAddress::from_str(address)?; | |
| } | |
| connection.config = bond.into() | |
| }; |
and maybe some DRY before we repeat it for every connection type:
macro_rules! ADD_MAC {
($connection:expr, $config:expr) => {
if let Some(address) = &$config.address {
$connection.mac_address = MacAddress::from_str(address)?;
}
};
}
...
if let Some(ethernet) = &self.ethernet {
ADD_MAC!(connection, ethernet);
connection.config = model::ConnectionConfig::Ethernet
}
...
Collaborator
Author
There was a problem hiding this comment.
WDYT of
impl TryFrom<&Option<String>> for MacAddress {
type Error = InvalidMacAddress;
fn try_from(value: &Option<String>) -> Result<Self, Self::Error> {
match &value {
Some(str) => MacAddress::from_str(str),
None => Ok(Self::Unset)
}
}
}
Owner
There was a problem hiding this comment.
Sure, should also work if you prefer it.
Collaborator
Author
There was a problem hiding this comment.
I finally go with
#serde(default)
address: String,
which lead to empty string if it isn't in xml...
Owner
There was a problem hiding this comment.
I finally go with
#serde(default) address: String,which lead to empty string if it isn't in xml...
In that case you should also add
#[serde(skip_serializing_if = "String::is_empty")]
Collaborator
Author
There was a problem hiding this comment.
valid point.
Lets see if this agama-project#983 gets accepted, then I go back to Option<String>
jcronenberg
approved these changes
Jan 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Upstream bonding was finally merged and now we can re-implement the migrate-wicked side.
Testing